<?php
class Index extends Action {
	private $limit = 15;
	/* (non-PHPdoc)
	 * @see Action::execute()
	 */
	public function execute($params) {
		check_login ( ADMIN_LOGIN_PAGE );
		$data = array ();
		$start = rqst ( 'start', 1 ); // 分页		
		$where = Model::where_build ( array ('name like','type' ), $data, array ('name' => 'like' ) );
		
		$wlM = new WebLinkModel ();
		
		$wlM->sort ( array ('link_id', 'd' ) );
		
		$wlM->where ( $where )->limit ( $this->limit, $start - 1 )->count ( true );
		$items = $wlM->retrieve ();
		$totalCount = 0;
		if ($items) {
			$data ['items'] = $items;
			$totalCount = $items->countTotal;
		} else {
			$data ['items'] = array ();
		}
		$data ['totalCount'] = $totalCount;
		$data ['limit'] = $this->limit;
		$data ['curl'] = $this->url;
		$data ['navi'] = 'links';
		$data ['page_tip_info'] = sess_del ( 'page_tip_info' );
		$types = CoreOptionModel::getOption ( 'link_types' );
		$data ['types'] = ! empty ( $types ) ? array_merge ( array ('未分类' ), explode(',', $types )) : array ('未分类' );		
		bind ( 'get_link_bench_options', array ($this, 'get_link_bench_options' ) );
		bind ( 'get_link_operation', array ($this, 'get_link_operation' ), 1, 2 );
		return new SmartyView ( $data, 'link/Index' );
	}
	public function get_link_bench_options($opt) {
		$opt .= '<li><a href="#" class="del-all-links"><i class="icon-trash"></i>删除</a></li>';
		$opt .= '<li><a href="#" class="set-all-display" rel="1"><i class="icon-eye-open"></i>设为可见</a></li>';
		$opt .= '<li><a href="#" class="set-all-display" rel="0"><i class="icon-eye-close"></i>设为不可见</a></li>';
		return $opt;
	}
	public function get_link_operation($opts, $item) {
		$opts .= '<a href="./?Ctlr=EditLink&lid=' . $item ['link_id'] . '"><i class="icon-edit"></i></a>';
		$opts .= '<a onclick="return confirm(\'你确定要删除该友情链接?\');" href="./?Ctlr=DelLink&lid=' . $item ['link_id'] . '"><i class="icon-trash"></i></a>';
		if ($item ['display']) {
			$opts .= '<a title="设为不可见" onclick="return confirm(\'你确定要隐藏该友情链接?\');" href="./?Ctlr=ShowLink&d=0&lid=' . $item ['link_id'] . '"><i class="icon-eye-close"></i></a>';
		} else {
			$opts .= '<a title="设为可见" onclick="return confirm(\'你确定要显示该友情链接?\');" href="./?Ctlr=ShowLink&d=1&lid=' . $item ['link_id'] . '"><i class="icon-eye-open"></i></a>';
		}
		return $opts;
	}
}